package ru.spb.osll.myfit.client.dialog;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;
import com.google.gwt.user.client.ui.VerticalPanel;
import ru.spb.osll.myfit.client.event.PageEvent;

import java.util.Vector;

abstract public class InputDialog extends DialogBox {
	
  protected SuggestBox m_suggestBox;	
  protected Button m_cbButtonOk;
  protected Button m_cbButtonCancel;	
  protected MultiWordSuggestOracle oracle;	
  protected Vector<Suggestion> suggestions;
  protected PageEvent m_sourceEvent = null;
  protected DialogEventListener m_listener;
  abstract public void defineItems ();
	
  public InputDialog(DialogEventListener listener) {
    m_listener = listener;
    oracle = new MultiWordSuggestOracle(".");  
    suggestions = new Vector<Suggestion>();
    oracle.setDefaultSuggestions(suggestions);

    m_suggestBox = new SuggestBox(oracle);
    m_suggestBox.setWidth("400px");

    VerticalPanel vPanel = new VerticalPanel();
    HorizontalPanel hPanel = new HorizontalPanel();
    hPanel.add(m_suggestBox);

    HorizontalPanel hPanelButton = new HorizontalPanel();
    hPanelButton.setSpacing(10);

    vPanel.add(hPanel);

    m_cbButtonOk = new Button();
    m_cbButtonCancel = new Button();
    m_cbButtonCancel.setText("Cancel");

    hPanelButton.add(m_cbButtonOk);
    hPanelButton.add(m_cbButtonCancel);
    hPanel.setStyleName("comboBoxStyle");
    hPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);

    vPanel.add(hPanel);
    vPanel.add(hPanelButton);

    this.setWidget(vPanel);
			
    m_cbButtonCancel.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {
        hide();
        m_sourceEvent = null;
      }
    });
  }
  
  public void setSourceEvent(PageEvent event){
    m_sourceEvent = event;
  }
}
